package com.arpa.wms.service.impl;

import com.arpa.ntocc.common.common.util.CommonUtil;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.wms.domain.dto.CountingItemDTO;
import com.arpa.wms.domain.entity.Container;
import com.arpa.wms.domain.entity.CountingItem;
import com.arpa.wms.domain.vo.CountingItemVO;
import com.arpa.wms.mapper.CountingItemMapper;
import com.arpa.wms.service.ICountingItemService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 领用单明细 服务实现类
 * @author jinss
 * @date 2020-08-20 14:30:42
 **/
@Service
public class CountingItemServiceImpl extends ServiceImpl<CountingItemMapper, CountingItem> implements ICountingItemService {


    /**
     * 查询合计,包含总数
     *
     * @param countingItemDTO
     * @return
     */
    @Override
    public CountingItemVO queryListSum(CountingItemDTO countingItemDTO) {
        return baseMapper.queryListSum(countingItemDTO);
    }
    @Override
    public List<CountingItemVO> queryList(CountingItemDTO countingItemDTO) {
        //排序字段名需要驼峰转数据库下划线类型字段名
        if(StringUtils.isNotEmpty(countingItemDTO.getSortField())){
            countingItemDTO.setSortField(CommonUtil.camel2Underline(countingItemDTO.getSortField()));
        }
        return baseMapper.queryList(countingItemDTO);
    }

    @Override
    public boolean updateStatus(String code,String status) {

        return this.update(new UpdateWrapper<CountingItem>().lambda().eq(CountingItem::getCode, code)
                .set(CountingItem::getStatus, status));
    }

    /**
     * 通过查询记录创建盘点明细
     * @param countingCode 盘点单号
     * @param userCode 操作人code
     * @param createdName 操作人姓名
     * @param warehouseCode 仓库标识
     * @param groupCode 机构标识
     * @param location 库位
     * @param shipmentCode 货主标识
     * @param actionNum 动线号
     */
    @Override
    public void insertBatch(String countingCode, String userCode, String createdName, String warehouseCode,
                            String groupCode, String location, String shipmentCode, Long actionNum) {
        baseMapper.insertBatch(countingCode,userCode,createdName,warehouseCode,groupCode,location,shipmentCode,actionNum);
    }
}
